import { _decorator, Component, director, Node } from 'cc';
import { init } from '../scene/init';
import { nodePool } from '../utils/nodePool';
import { gameConfig } from '../data/gameConfig';
import { emits } from '../data/enums';
import { game } from '../scene/game';
const { ccclass, property } = _decorator;

@ccclass('shopView')
export class shopView extends Component {
    @property(Node)
    listNode = null;
    private txPage = 1;
    private pageItemNum = 6; //每一页头像数
    start() {
        this.initList();
    }
    //刷新列表
    initList(type: number = 1) {
        switch (type) {
            case 1:
                //刷新头像列表
                this.refreshTx();
                break;
            case 2:
                //收藏品
                break;
            case 3:
                //个人专属
                break;
        }
    }
    close() {
        nodePool.ins.huiShouNode(this.node);
    }
    refreshTx() {
        this.listNode.removeAllChildren();
        const start = (this.txPage - 1) * this.pageItemNum;
        const end = start + this.pageItemNum;
        const curPage = gameConfig.txList.slice(start, end);
        for (let i = 0; i < curPage.length; i++) {
            let item = nodePool.ins.getPoolNode("txItem", this.listNode);
            let ts: any = item.getComponent("txItem");
            ts.txNum = curPage[i].txNum;
            ts.isGet = curPage[i].isGet;
            ts.jinbiNum = curPage[i].price;
            ts.init();
        }
    }
    ClickR() {
        if (this.txPage == Math.ceil(gameConfig.txList.length / this.pageItemNum)) {
            return;
        }
        this.txPage++;
        this.refreshTx();
    }
    ClickL() {
        if (this.txPage == 1) {
            return;
        }
        this.txPage--;
        this.refreshTx();
    }
    clickPet(){
        nodePool.ins.getPoolNode("toast", this.node.parent);
        director.emit(emits.toast, "暂未开发");
    }
}


